package com.longdaji.decoration.ui.activitiesOfMine.feedback;

import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.longdaji.decoration.R;
import com.longdaji.decoration.base.BaseFragment;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Kanade on 2018/5/2 0002.
 */

public class DoFeedbackFragment extends BaseFragment implements DoFeedbackContract.IView {
    @Inject
    public DoFeedbackFragment() {
    }

    @Inject
    DoFeedbackContract.IPresenter mPresenter;

    @BindView(R.id.et_feedback_content)
    EditText etFeedbackContent;
    @BindView(R.id.et_contact_way)
    EditText etContactWay;
    @BindView(R.id.btn_confirm)
    Button btnConfirm;

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_do_feedback;
    }

    @Override
    protected void initView() {
        if (mPresenter != null)
            mPresenter.setView(this);
        etFeedbackContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.length() > 0) {
                    btnConfirm.setEnabled(true);
                } else {
                    if (!btnConfirm.isEnabled())
                        btnConfirm.setEnabled(false);
                }
            }
        });

        etContactWay.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.length() > 0) {
                    btnConfirm.setEnabled(true);
                } else {
                    if (!btnConfirm.isEnabled())
                        btnConfirm.setEnabled(false);
                }
            }
        });
    }

    @OnClick({R.id.btn_confirm})
    void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_confirm:
                mPresenter.doFeedback(etFeedbackContent.getText().toString(), etContactWay.getText().toString());
                break;
            default:
                break;
        }
    }

    @Override
    public void showDoFeedbackSuccess() {
        etFeedbackContent.setText("");
        Toast.makeText(getActivity(), "反馈成功,感谢您的意见!", Toast.LENGTH_SHORT).show();
    }
}
